<?php
class CommentAction extends AdminAction {
    //广告管理
	public function index(){
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		import("ORG.Util.Page");
		$comment=D('CommentView');
		$count = $comment->count();
		$page = new Page($count,15);
		$list = $comment->limit($page->firstRow.",".$page->listRows)->order('comtime desc')->select();
		foreach($list as $key => $val){
			switch ($val['comtype'])
			{
				case 1:$list[$key]['comtype']="图片";break;
				case 2:$list[$key]['comtype']="视频";break;
				case 3:$list[$key]['comtype']="动画";break;
				case 4:$list[$key]['comtype']="游戏";break;
				case 5:$list[$key]['comtype']="文章";break;
				case 6:$list[$key]['comtype']="挂图";break;
				case 7:$list[$key]['comtype']="图书";break;
				case 8:$list[$key]['comtype']="展品";break;
				case 9:$list[$key]['comtype']="知识题";break;
				default:$list[$key]['comtype']="其他";
			}
		}
		$this->assign("page",$page->show());
		$this->assign("list",$list);
		$this->display();
	}
	
   
	  public function move(){
	  $isLogin = session(C('ADMIN_AUTH_KEY'));
	  if(!$isLogin) $this->redirect('User/login');
	    if($_GET['comid']){
		    $fid['comid']=$_GET['comid'];
		    $model=D('Comment');
		 	$model->where($fid)->delete();

			$this->redirect('Comment/index');
	    }else{
			$this->redirect('Comment/index');
	    }
	    
	  }
   
	//禁用
	public function forbidden()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$comid= $_POST['comid'];
		
		if($comid)
		{
			$map['comid'] = $comid;
			//$map["status"] = 1;
			$data["comstatus"] = 1;
			$res = M('Comment')->where($map)->save($data);
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
	
	//启用
	public function enable()
	{
		$isLogin = session(C('ADMIN_AUTH_KEY'));
		if(!$isLogin) $this->redirect('User/login');
		$comid= $_POST['comid'];
		
		if($comid)
		{
			$map['comid'] = $comid;
			//$map["status"] = 1;
			$data["comstatus"] = 0;
			$res = M('Comment')->where($map)->save($data);
			if($res) echo 1;
			else echo 0;
		}

		else echo 0;
	}
}